#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

const int maxn = 1010, INF = 0x3f3f3f;
int G[maxn][maxn], d[maxn], n, m, k;
// G邻接矩阵存储图  d保存源点到各个顶点的当前最短路径长度
bool vis[maxn];
vector<int> path;

bool dijkstra(int s) {
    fill(d, d + maxn, INF);
    fill(vis, vis + maxn, 0);
    d[s] = 0;
    for (int i = 0; i < n; i++) {
        int MIN = INF, u = -1;
        for (int j = 1; j <= n; j++) {
            if (vis[j] == false && d[j] < MIN) {  // j没访问过 且源点到j有路径
                u = j;
                MIN = d[j];
            }
        }
        if (u == -1 || d[u] != d[path[i]]) return false;
        vis[u] = true;
        for (int v = 1; v <= n; v++) {
            if (vis[v] == false && G[u][v] != INF) {
                if (d[u] + G[u][v] < d[v]) {
                    d[v] = d[u] + G[u][v];
                }
            }
        }
    }
    return true;
}
int main() {
    cin >> n >> m;
    fill(G[0], G[0] + maxn * maxn, INF);
    for (int i = 1; i <= m; i++) {
        int a, b, w;
        cin >> a >> b >> w;
        G[a][b] = G[b][a] = w;
    }

    cin >> k;
    for (int i = 0; i < k; i++) {
        path.clear();
        for (int j = 0; j < n; j++) {
            int a;
            cin >> a;
            path.push_back(a);
        }
        int st = path[0];
        if (dijkstra(st))
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}
